package com.controll.xstream;

import com.bean.xstream.user.UserMsg;
import com.bean.xstream.user.UserVo;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

public class ParseBean2Xml {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		XStream xstream = new XStream();
//		xstream.setMode(XStream.ID_REFERENCES);
//		xstream.alias("userVo", UserVo.class);
//		xstream.aliasPackage("test.com", "com.bean");
		
		xstream.processAnnotations(UserVo.class);
		
//		xstream.aliasField("tempField", UserVo.class, "userMsg");
		
		UserVo userVo = new UserVo();
		userVo.setAcc("acc");
		userVo.setEmail("email");
				
		UserMsg userMsg = new UserMsg();
		userMsg.setRetCode("1");
		userMsg.setRetMsg("value1");
		userVo.setUserMsg(userMsg);
		
		String xml = xstream.toXML(userVo);

		System.out.println(xml);
		
		//JSON Ex.
//		String jsonStr = "{\"userVo\":{\"acc\":\"test\", \"email\":\"testMail\"}}";
//		XStream jsonStream = new XStream(new JettisonMappedXmlDriver());
//
//		jsonStream.alias("userVo", UserVo.class);
//		UserVo jsonVo = (UserVo) jsonStream.fromXML(jsonStr);
//		System.out.println(jsonVo.getAcc());
		
	}

}
